// package com.assessment.controller;
//
// import com.assessment.cas.CASAutoConfig;
// import com.assessment.entity.Auser;
// import com.assessment.service.AuserService;
// import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
// import io.swagger.annotations.Api;
// import org.jasig.cas.client.authentication.AttributePrincipal;
// import org.jasig.cas.client.validation.Assertion;
// import org.springframework.beans.factory.annotation.Autowired;
// import org.springframework.stereotype.Controller;
// import org.springframework.ui.ModelMap;
// import org.springframework.web.bind.annotation.CrossOrigin;
// import org.springframework.web.bind.annotation.PostMapping;
// import org.springframework.web.bind.annotation.RequestMapping;
// import org.springframework.web.bind.annotation.RestController;
//
// import javax.servlet.http.HttpServletRequest;
// import javax.servlet.http.HttpSession;
// import java.net.URLEncoder;
// import java.util.HashMap;
// import java.util.Iterator;
// import java.util.Map;
//
// import static com.assessment.utils.Constant.LOGIN_FAILED;
// import static com.assessment.utils.ReturnMap.failedMap;
// import static com.assessment.utils.ReturnMap.successMap;
// import static java.lang.System.out;
//
// @CrossOrigin("*")
// @RestController
// @Api(tags={"登录"})
// @RequestMapping("/admin")
// public class CasController {
//     private final CASAutoConfig casAutoConfig;
//
//     private final AuserService service;
//
//     public CasController(AuserService service, CASAutoConfig casAutoConfig) {
//         this.service = service;
//         this.casAutoConfig = casAutoConfig;
//     }
//
//     @RequestMapping(path = {"/login"})
//     public Map<String, Object> login(HttpServletRequest request){
//         HttpSession session = request.getSession();
//         String loginName = (String)session.getAttribute("cas.client.user");
//         Assertion assertion = (Assertion)session.getAttribute("_const_cas_assertion_");
//         Map<String, Object> userInfo = new HashMap<>();
//
//         //Test.test(assertion);
//         if (assertion != null){
//             AttributePrincipal principal = assertion.getPrincipal();
//             Map<String,Object> attributemap = principal.getAttributes();//获得认证中心传过来的其它用户属性。一般为空
//
//             if(attributemap != null) {
//                 userInfo.put("attributemap", attributemap);
//                 Iterator<String> iter = attributemap.keySet().iterator();
//                 while(iter.hasNext()) {
//                     String key = iter.next();
//                     out.println(key + "  " + attributemap.get(key) );
//                 }
//
//             }
//             String loginName_ = principal.getName();//获得认证中心传过来的认证名，一般为用户登录名
//             out.println("登录成功，欢迎您："+loginName_);
//             userInfo.put("loginName_", loginName_);
//         }
//         String remoteUser= request.getRemoteUser();
//         userInfo.put("remoteUser", remoteUser);
//         out.println("remoteUser："+remoteUser);
//         if (loginName != null && loginName.trim().length() > 0){
//             //System.out.println("登录成功");
//             out.println("登录成功，欢迎您："+loginName);
//             userInfo.put("remoteUser", remoteUser);
//             QueryWrapper<Auser> auserQueryWrapper = new QueryWrapper<>();
//             auserQueryWrapper.eq("account", loginName);
//             Auser one = service.getOne(auserQueryWrapper);
//             userInfo.put("one", one);
//             if (one == null) return failedMap(LOGIN_FAILED);
//             one.setPwd("");
//             return successMap("登录成功!",one);
//         }else{
//             //System.out.println("登录失败");
//             out.println(LOGIN_FAILED);
//             return failedMap(LOGIN_FAILED);
//         }
//     }
//     @RequestMapping(path = {"/logout"})
//     public String logout(HttpServletRequest request){
//         return "redirect:"+casAutoConfig.getCasServerLogoutUrl()+ "?service=" + URLEncoder.encode(casAutoConfig.getServerName() + "login");
//     }
// }
